package com.lbssoft.gpsbd.task;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 定时任务配置类
 */
@Configuration
@EnableScheduling // 启用定时任务
public class SchedulingConfig implements SchedulingConfigurer {

	 	@Override
	    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
	        taskRegistrar.setScheduler(taskExecutor());
	    }
	    
	    @Bean(destroyMethod="shutdown")
	    public Executor taskExecutor() {
	        return Executors.newScheduledThreadPool(100);
	    }

		//0 50 23 * * ? 每天23:50:00
		//0 * * * * ? 一分钟一次
		//0 0 0/1 * * ?  一小时一次
		@Scheduled(cron = "0 50 23 * * ? ") // 23:59:00
		@Async
		public void statisticsTrip() {
			ScheduledTask task = new ScheduledTask();
			task.deviceStatistics();

    	}


}
